home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fdform18.zip / DISKIO.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-21  |  14KB  |  415 lines

  1. {$A+,B-,D+,E-,F+,I-,L+,N-,O+,R-,S-,V-,X+}
  2.  
  3. UNIT diskio;
  4.  
  5. INTERFACE
  6.  
  7. USES dos,auxdos;
  8.  
  9. TYPE Split      = RECORD
  10.                     O: Word;
  11.                     S: Word;
  12.                   END;
  13.  
  14. TYPE filtyp     = FILE OF ARRAY[0..511] OF Byte;
  15.      fileptr    = ^filtyp;
  16.      boottyp    = ARRAY[62..511] OF Byte;
  17.  
  18. TYPE bpbtyp     =  RECORD
  19.                      jmp: ARRAY[1..3] OF Byte;                     {Die ersten drei Bytes für JUMP}
  20.                      oem: ARRAY[1..8] OF Char;                                        {OEM-Eintrag}
  21.                      bps: Word;                                                  {Bytes pro Sektor}
  22.                      spc: Byte;                                              {Sektoren pro Cluster}
  23.                      res: Word;                                                     {BOOT-Sektoren}
  24.                      fat: Byte;                                                  {Anzahl der FAT's}
  25.                      rde: Word;                                          {Basisverzeichniseinträge}
  26.                      sec: Word;                                       {Gesamtsektoren der Diskette}
  27.                      mds: Byte;                                                  {Media-Deskriptor}
  28.                      spf: Word;                                                  {Sektoren pro FAT}
  29.                      spt: Word;                                                 {Sektoren pro Spur}
  30.                      hds: Word;                                                            {Seiten}
  31.                      shh: Longint;                                            {Versteckte Sektoren}
  32.                      lsc: Longint;                     {Anzahl der Sektoren bei großen Partitionen}
  33.                      pdn: Word;                                             {Physical Drive Number}
  34.                      ebs: Byte;                                           {Extended Boot Signature}
  35.                      vsn: LongInt;                                           {Volume Serial-Number}
  36.                      vlb: ARRAY[1..11] OF Char;                                      {Volume Label}
  37.                      fsi: ARRAY[1..8] OF Char;                                     {File System Id}
  38.                      boot_code: boottyp;                                     {Puffer für BOOT-Code}
  39.                    END;
  40.  
  41.       bdib      = RECORD
  42.                     flag   : Byte;                                                {Bitmapped flags}
  43.                     dtyp   : Byte;                                                     {Drive Type}
  44.                     dflag  : Word;                                                {Bitmapped flags}
  45.                     noc    : Word;                                            {Number of cylinders}
  46.                     mt     : Byte;                                                     {Media Type}
  47.                     bpb    : ARRAY[0..30] OF Byte;                                            {BPB}
  48.                     nos    : Word;                                    {Number of sectors per track}
  49.                     sly    : ARRAY[0..63] OF RECORD                                 {sector layout}
  50.                                                  num: Word;                         {Sector Number}
  51.                                                  siz: Word;                        {Size of sector}
  52.                                                END;
  53.                   END;
  54.  
  55.       dos4rw    = RECORD                                                   {Disk Read/Write Packet}
  56.                     sector   : LongInt;                                     {für Partitionen >=32M}
  57.                     count    : Word;
  58.                     Transfer : Pointer;
  59.                   END;
  60.  
  61. TYPE  SectorTyp = Object
  62.                     data: Pointer;
  63.                     Start: LongInt;
  64.                     datalen: Word;
  65.                     Constructor init(VAR allocated: Boolean);
  66.                     PROCEDURE Error(lw,rw,err:Byte; VAR er:Boolean; Sector:Longint); virtual;
  67.                     PROCEDURE DiskRw(rw,lw:Byte; Sector:LongInt; Count:Byte; Transfer:Pointer);
  68.                     PROCEDURE Readx(lw: Byte; x: LongInt);
  69.                     PROCEDURE Writex(lw: Byte; x: LongInt);
  70.                     Destructor Done;
  71.                   END;
  72.  
  73.  
  74. TYPE CylTyp    = Object (SectorTyp)
  75.                    Constructor init(spcyl: Word; VAR allocated: Boolean);
  76.                    PROCEDURE Readx(lw: Byte; x: Word);
  77.                    PROCEDURE Writex(lw: Byte; x: Word);
  78.                  END;
  79.  
  80.  
  81. TYPE BootSecTyp = Object(SectorTyp)
  82.                     bpb: ^bpbtyp;
  83.                     status: Word;
  84.                     Media: Byte;
  85.                     UnknownDrive: Boolean;
  86.                     dos4: Boolean;
  87.                     Constructor init(VAR allocated: Boolean);
  88.                     PROCEDURE Readx(lw: Byte);
  89.                     PROCEDURE Writex(lw: Byte);
  90.                     PROCEDURE Remount(lw: Byte);
  91.                   END;
  92.  
  93. TYPE STyp       = ARRAY[0..0] OF ^SectorTyp;
  94.      CTyp       = ARRAY[0..0] OF ^CylTyp;
  95.      Smtyp      = ^Styp;
  96.      Cmtyp      = ^CTyp;
  97.  
  98.  
  99.  
  100. VAR BootSec         : BootSecTyp;
  101.   maxsec            : Word;
  102.   maxcyl            : Word;
  103.  
  104.  
  105.   PROCEDURE CheckDrive(lw:Byte; VAR Status:Word; VAR error1:Boolean; VAR Media:Byte);
  106.   PROCEDURE DeallocCyl(Var Cylmem:Cmtyp; Stop:Word);
  107.   PROCEDURE DeallocSec(Var Secmem:Smtyp; Stop:Word);
  108.   FUNCTION AllocCyl(VAR Cylmem:Cmtyp; Stop:Word): Word;
  109.   FUNCTION AllocSec(VAR secmem:Smtyp; stop:Word): Word;
  110.   FUNCTION ReadKey: Char;
  111.  
  112. IMPLEMENTATION
  113.  
  114.   FUNCTION ReadKey:Char; Assembler;
  115.     ASM
  116.       mov   ah,8
  117.       int   21h
  118.     END;
  119.  
  120.   PROCEDURE Sectortyp.error(lw,rw,err:Byte; VAR er:Boolean; Sector:Longint);
  121.   VAR chx: Char;
  122.   BEGIN
  123.     WITH BootSec DO BEGIN
  124.       WriteLn(stderr);
  125.       IF rw=0 THEN
  126.         Write(stderr,'Read')
  127.       ELSE
  128.         Write(stderr,'Write');
  129.       Write(stderr,'-Error Drive ',chr(lw+$40),': ');
  130.       CASE err OF
  131.         $00: Write(stderr,'Disk is write protected');
  132.         $01: Write(stderr,'Unknown unit');
  133.         $02: Write(stderr,'Drive not ready');
  134.         $03: Write(stderr,'Unknown command');
  135.         $04: Write(stderr,'Bad CRC');
  136.         $05: Write(stderr,'Bad request structure length');
  137.         $06: Write(stderr,'Seek error');
  138.         $07: Write(stderr,'Unknown media type');
  139.         $08: Write(stderr,'Sector not found');
  140.         $09: Write(stderr,'Printer out of paper');
  141.         $0A: Write(stderr,'Write fault');
  142.         $0B: Write(stderr,'Read fault');
  143.         $0C: Write(stderr,'General failure');
  144.         $0D: Write(stderr,'Sharing violation');
  145.         $0E: Write(stderr,'Lock violation');
  146.         $0F: Write(stderr,'Invalid disk change');
  147.         $10: Write(stderr,'FCB unavailable');
  148.         $11: Write(stderr,'Sharing buffer overflow');
  149.         ELSE Write(stderr,'Unknown error');
  150.       END;
  151.       Writeln(stderr,'.');
  152.       Write(stderr,'Error ',err,': Sector: ',Sector,' ');
  153.       IF Sector=0 THEN
  154.         WriteLn(stderr,'BOOT-Sector')
  155.       ELSE BEGIN
  156.         IF (Sector>=1) and (Sector<=bpb^.spf) THEN
  157.           WriteLn(stderr,'FAT 1');
  158.         IF (Sector>=bpb^.spf+1) and (sector<=Longint(bpb^.spf) shl 1) THEN
  159.           WriteLn(stderr,'FAT 2');
  160.       END;
  161.       REPEAT
  162.         Write(stderr,'(A)bort, (R)etry, (I)gnore ? ');
  163.         chx:=Upcase(ReadKey); WriteLn(stderr,chx);
  164.       UNTIL chx IN ['A','I','R'];
  165.       CASE chx OF
  166.         'A': Halt(255);
  167.         'I': BEGIN
  168.                er:=False;
  169.              END;
  170.         'R': er:=True;
  171.       END;
  172.     END;
  173.   END;
  174.  
  175.   Constructor SectorTyp.init(VAR allocated: Boolean);
  176.   BEGIN
  177.     allocated:=True;
  178.     IF MaxAvail<512 THEN allocated:=False;
  179.     IF allocated THEN BEGIN
  180.       GetMem(self.data,512);
  181.       datalen:=512;
  182.     END;
  183.   END;
  184.  
  185.   PROCEDURE int2526(rw,lw:Byte; Sector:Longint; Count:Word; Transfer:Pointer; Var flags,rax: Word); Far;
  186.   LABEL common;
  187.   VAR rwpacket: dos4rw;
  188.   BEGIN
  189.     IF NOT(BootSec.Dos4) THEN BEGIN
  190.       ASM
  191.